package LeetCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class LC_015_3Sum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String[] arr = sc.nextLine().trim().split("\\s+");
            int[] a = new int[arr.length];
            for (int i = 0; i < a.length; i++) {
                a[i] = Integer.parseInt(arr[i]);
            }
            System.out.println(threeSum(a));
        }
        sc.close();
    }

    private static List<List<Integer>> threeSum(int[] nums) {
        List<List<Integer>> ansList = new ArrayList<>();
        if (nums.length < 3)
            return ansList;
        Arrays.sort(nums);
        for (int i = 0; i < nums.length - 2; i++) {
            if (i == 0 || nums[i - 1] < nums[i]) {
                int st = i + 1;
                int en = nums.length - 1;
                while (st < en) {
                    int sum = nums[i] + nums[st] + nums[en];
                    if (sum == 0) {
                        ansList.add(Arrays.asList(nums[i], nums[st], nums[en]));
                        st++;
                        en--;
                        while (st < en && nums[st] == nums[st - 1])
                            st++;
                        while (st < en && nums[en] == nums[en + 1])
                            en--;
                    } else if (sum > 0)
                        en--;
                    else
                        st++;
                }
            }
        }
        return ansList;
    }
}